<?php
/**
 * Created by PhpStorm.
 * User: xuke
 * Date: 16/7/19
 * Time: 上午11:40
 */

namespace App\Services;


class Curl
{

    /**
     * @param $url
     * @param array $data
     * @param int $type 0get方式,1post方式
     * @param int $timeout
     * @return mixed
     */
    public static function curl_https($url, $data=[], $type=0, $timeout=30)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);  // 从证书中检查SSL加密算法是否存在
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);

        if ($type ==1 )  //提交方式为post提交
        {
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        }

        $response = curl_exec($ch);

        if($error=curl_error($ch)){
            die($error);
        }

        curl_close($ch);

        return $response;
    }
    
    



}